Docker Containers (includes Content Update Program) by Christopher Negus

Docker Containers (includes Content Update Program) by Christopher Negus

Author:Christopher Negus
Language: eng
Format: epub
Publisher: Pearson Education Limited (US titles)
Published: 2016-03-16T04:00:00+00:00


Click here to view code image

# docker run -d --name=link-test myrepo/fedora-httpd

Notice that I run the container in detached mode with the -d parameter (and not interactively on a TTY with -it).

Next I run a second container that I name linked and link it to link-test. I’m mapping the link to the name lt (short for link-test). This is the name I use from inside the second container to access port 80 in the first container.

Click here to view code image

# docker run -it --link=link-test:lt --name=linked fedora:22 bash

I don’t have to name this second container, but it’s good practice to do so. From within this second container, running the env (environment) command shows the following:

Click here to view code image

bash-4.2# env

HOSTNAME=d71eb38e62d5

TERM=xterm

LT_PORT_80_TCP=tcp://172.17.0.3:80

LT_PORT_80_TCP_PORT=80

LT_PORT_80_TCP_PROTO=tcp

LT_PORT=tcp://172.17.0.3:80

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

PWD=/

container_uuid=d71eb38e-62d5-0a15-902c-6901a4ed5d26

LT_NAME=/linked/lt

SHLVL=1

HOME=/root

LT_PORT_80_TCP_ADDR=172.17.0.3

_=/usr/bin/env

Notice that there are several environment variables starting with LT. Those variable names are derived from the lt string I assigned to the link name in the docker run command. Any port exposed from the first container is accessible from the new container in the same way.

Now I can use the curl command to leverage the link between the two containers and display the html page available on port 80 of the container named lt or link-test. I only show the first few lines here:

Click here to view code image

bash-4.2# curl http://lt

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/

xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

<title>Test Page for the Apache HTTP Server on Fedora</title>

...

Links are a powerful tool for linking containers together. In the next section I build up a scenario.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.